<?php
declare (strict_types=1);

namespace app\admin\controller;

use app\common\facade\Builder;

class MakePlace extends Base
{
    //主键，默认为id
    protected string $pk = 'id';

    //主模型
    protected string $model = '\app\common\model\MakePlace';

    protected array $hasOne = ['user'];

    protected array $append = ['statusText'];

    public function index(): string
    {
        //构建表格数据
        return Builder::Table()
            ->addColumn(['type' => 'checkbox', 'title' => '全选', 'fixed' => 'left'])
            ->addColumn(['field' => 'id', 'sort' => true, 'title' => 'ID', 'width' => 80])
            ->addColumn(['field' => 'uid', 'title' => '申请会员', 'templet' => '#_userTpl', 'width' => 250])
            ->addColumn(['field' => 'title', 'title' => '分销商名称'])
            ->addColumn(['field' => 'mobile', 'title' => '手机号'])
            ->addColumn(['field' => 'create_time', 'title' => '申请时间'])
            ->addColumn(['field' => 'admin_name', 'title' => '审核人'])
            ->addColumn(['field' => 'examine_time', 'title' => '审核时间'])
            ->addColumn(['field' => 'statusText', 'title' => '状态'])
            ->addTopButtons([
                'batchAudit' => [
                    'title' => '批量通过', 'icon' => 'layui-icon-util',
                    'url'   => url('makePlace/batch')->build(),
                    'event' => '_batchSubmit',
                    'class' => 'normal',
                ],
                'batchFail'  => [
                    'title' => '批量驳回', 'icon' => 'layui-icon-util',
                    'url'   => url('makePlace/batchFail')->build(),
                    'event' => '_batchSubmit'
                ],
            ])
            ->addSearch([
                ['uid', '会员编号/昵称/手机号', 'input', '', '\app\common\model\User', 'code|nickname|mobile,id'],
            ])
            ->fetch();
    }

    public function batch()
    {
        return $this->model::batch($this->request->param('ids'), $this->admin, 2);
    }

    public function batchFail()
    {
        return $this->model::batch($this->request->param('ids'), $this->admin, 3);
    }

}
